package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.woniuxy.ResponseEntity.ResponseEntity;
import com.woniuxy.dao.ShiroDao;
import com.woniuxy.entity.Rbacmanager;
import com.woniuxy.service.ShiroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional
@Service
public class ShiroServiceImpl implements ShiroService {
    @Autowired(required = false)
    ShiroDao sdao;
    @Override
    public ResponseEntity findAll(int currentPage,int pageSize,Rbacmanager Rbacmanager) {
        //这个参数封装了分页参数和对象参数
        //这个是分页查询
        PageHelper.startPage(currentPage,pageSize);
        System.out.println(Rbacmanager);

        //数据查询
        List<Rbacmanager> rbac = sdao.findAll(Rbacmanager);

        //现在使用PageInfo.of(rbac);是最新版本写的方式，可以直接获得各种分页信息和数据
        //将数据和分页信息一起封装了
        PageInfo<Rbacmanager> pageInfo = PageInfo.of(rbac);

        //创建返回类型对象
        ResponseEntity<PageInfo> response = new ResponseEntity<>();
        //如果查询到的数据不为空，就将分页信息和数据一起封装进返回类型对象中去
        if(rbac.size() > 0){
            response.setData(pageInfo);
            response.setCode(200);
            response.setMessage("查询成功");
        }else {
            response.setData(null);
            response.setCode(500);
            response.setMessage("查询失败");
        }

            return response;
    }

    @Transactional
    @Override
    public boolean deleteById(int id) {
        int num=sdao.deleteById(id);
        return num>0;
    }

    @Override
    public boolean addRbac(Rbacmanager rbace) {
        int num=sdao.addRbac(rbace);
        return num>0;
    }

    @Override
    public boolean update(Rbacmanager rbace) {
        int num=sdao.update(rbace);
        return num>0;
    }


}
